package com.lanling.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanling.eduservice.entity.EduCourse;
import com.lanling.eduservice.entity.EduTeacher;
import com.lanling.eduservice.orther.R;
import com.lanling.eduservice.service.EduCourseService;
import com.lanling.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 胡振华
 * @date 2020-11-25 21:30
 */
@RestController
@CrossOrigin
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    //分页查询讲师
    @GetMapping("/getTeacherPageList/{page}/{limit}")
    public R getTeacherPageList(@PathVariable long page, @PathVariable long limit){
        Page<EduTeacher> eduTeacherPage = new Page<>(page,limit);
        Map<String,Object> map = eduTeacherService.getTeacherPageList(eduTeacherPage);
        return R.ok().data(map);
    }

    //根据讲师id查询讲师详细信息
    @GetMapping("getTeacherFrontInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable String id){
        //根据讲师id查询讲师详细信息
        EduTeacher eduTeacher = eduTeacherService.getById(id);

        //根据讲师id查询讲师所讲课程
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id",id);
        List<EduCourse> eduCourseList = eduCourseService.list(queryWrapper);

        return R.ok().data("teacher",eduTeacher).data("eduCourseList",eduCourseList);
    }

}